<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" placeholder="请输入用户名">
    <button id="showBtn">显示用户名</button>
    <script>
        const input = document.querySelector('input');
            const showBtn = document.querySelector('#showBtn');
        showBtn.addEventListener('click', function() {
                if (input.type === 'password') {
                input.type = 'text';
                showBtn.innerText = '显示用户名';
            } else {
                    input.type = 'password';
                    showBtn.innerText = '隐藏用户名';
            }
            });
    </script>
</body>
</html>